import { addToShoppingCar, getCurrentGood } from '@/api'
import {getUUID_TOKEN}  from '@/utils/uuid_token.js'
const state = {
    userID:getUUID_TOKEN(),
    good: {},
}
const mutations = {
    GetCurrentGood(state, val) {
        state.good = val
    },
}
const actions = {
    async getCurrentGoodInfo({ commit }, skuId) {
        let result = await getCurrentGood(skuId)
        if (result.code = "200") {
            commit('GetCurrentGood', result.data)
        }
    },
    async addShoppingToCar({ }, { skuId, skuNum }) {
        let result = await addToShoppingCar(skuId, skuNum)
        if (result.code == '200') {
            return 'ok'
        } else {
            return new Promise(Error('请求失败!'))
        }
    },
}
const getters = {
    categoryView(state) {
        return state.good.categoryView || {}
    },
    skuInfo(state) {
        return state.good.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.good.spuSaleAttrList || {}
    },

}

export default {
    namespaced: true,
    state, mutations, actions, getters
}